<%--                                                                       --%>
<%-- Copyright (c) 2002-2003 BroadVision, Inc.  All rights reserved.       --%>
<%--                                                                       --%>
<%-- This software is copyrighted. Under the copyright laws, this software --%>
<%-- may not be copied, in whole or in part, without prior written consent --%>
<%-- of BroadVision, Inc. or its assignees. This software is provided      --%>
<%-- under the terms of a license between BroadVision and the recipient,   --%>
<%-- and its use is subject to the terms of that license.                  --%>
<%--                                                                       --%>
<%-- This software may be protected by one or more U.S. and International  --%>
<%-- patents.  Certain applications of BroadVision One-To-One software are --%>
<%-- covered by U.S. patent 5,710,887.                                     --%>
<%--                                                                       --%>
<%-- TRADEMARKS: BroadVision and BroadVision One-To-One are registered     --%>
<%-- trademarks of BroadVision, Inc., in the United States and the         --%>
<%-- European Community, and are trademarks of BroadVision, Inc., in other --%>
<%-- countries.  The BroadVision logo, is a trademark of BroadVision,      --%>
<%-- Inc., in the United States and other countries.                       --%>
<%--                                                                       --%>

<%@ page language="java" %>

<%@ taglib uri="/WEB-INF/struts-html.tld" prefix="html" %>
<%@ taglib uri="/WEB-INF/struts-logic.tld" prefix="logic" %>
<%@ taglib uri="/WEB-INF/struts-bean.tld" prefix="bean" %> 
<%@ taglib uri="/WEB-INF/bv-html.tld" prefix="bvhtml" %>


<script language=JavaScript>
<!--

// Gets user's confirmation to delete the task
function confirmDelete()
{
   if (confirm('<bean:message key="cs.checklist.confirmDeleteTask"/>'))
   {
      return true;
   }
   else
   {
      return false;
   }
}

function onClickButton(theForm, url) {
  theForm.action = url;
  theForm.submit();
}


////////////////// client browser detection //////////////////////////////////
  
  // convert all characters to lowercase to simplify testing
  var agt=navigator.userAgent.toLowerCase();

  // *** BROWSER VERSION ***
  // Note: On IE5, these return 4, so use is_ie5up to detect IE5.
  var is_major = parseInt(navigator.appVersion);

  var is_nav  = ((agt.indexOf('mozilla')!=-1) && (agt.indexOf('spoofer')==-1)
				&& (agt.indexOf('compatible') == -1) && (agt.indexOf('opera')==-1)
				&& (agt.indexOf('webtv')==-1) && (agt.indexOf('hotjava')==-1));
  var is_nav2 = (is_nav && (is_major == 2));
  var is_nav3 = (is_nav && (is_major == 3));
  var is_nav4 = (is_nav && (is_major == 4));
  var is_nav4up = (is_nav && (is_major >= 4));
  var is_navonly = (is_nav && ((agt.indexOf(";nav") != -1) ||
				   (agt.indexOf("; nav") != -1)) );
  var is_nav6 = (is_nav && (is_major == 5));
  var is_nav6up = (is_nav && (is_major >= 5));
  var is_gecko = (agt.indexOf('gecko') != -1);

  var is_ie     = ((agt.indexOf("msie") != -1) && (agt.indexOf("opera") == -1));
  var is_ie3    = (is_ie && (is_major < 4));
  var is_ie4    = (is_ie && (is_major == 4) && (agt.indexOf("msie 5")==-1) );
  var is_ie4up  = (is_ie  && (is_major >= 4));
  var is_ie5    = (is_ie && (is_major == 4) && (agt.indexOf("msie 5.0")!=-1) );
  var is_ie5_5  = (is_ie && (is_major == 4) && (agt.indexOf("msie 5.5") !=-1));
  var is_ie5up  = (is_ie  && !is_ie3 && !is_ie4);
  var is_ie5_5up =(is_ie && !is_ie3 && !is_ie4 && !is_ie5);
	
/////////////////////  end of client browser detection  //////////////////////

// swap 2 div vertically
function swap2Div(divName1, divName2) {
  var obj1, obj2, temp, dy;
  
  if (is_ie4up) {
    obj1 = document.all[divName1];
    obj2 = document.all[divName2];
	
    dy = obj2.offsetTop - obj1.offsetTop;
    obj1.style.pixelTop += dy;    obj2.style.pixelTop -= dy;
	  
  } else if (is_nav6up) {
    obj1 = document.getElementById(divName1);  
    obj2 = document.getElementById(divName2); 
	
    dy = obj2.offsetTop - obj1.offsetTop;
	
    obj1.style.top = ( parseInt(obj1.style.top, 10) + dy ) + "px";    
    obj2.style.top = ( parseInt(obj2.style.top, 10) - dy ) + "px"; 
	
  } else if (is_nav4up) {
    obj1 = document.layers[divName1];	
    obj2 = document.layers[divName2];
	
    dy = obj2.pageY - obj1.pageY;
    obj1.top += dy;   obj2.top -= dy;
		 
  } else {
    alert("Please use Internet Explorer 4+ or Netscape Navigator 4+ to view these pages.");
    window.close();  // close window to prevent further errors
  } 
}

//swap 2 rows
function swap2Row(lowerID, upperID) { 
  swap2Div("divTask_"+lowerID,    "divTask_"+upperID);
  swap2Div("divOwner_"+lowerID,   "divOwner_"+upperID);
  swap2Div("divDueDate_"+lowerID, "divDueDate_"+upperID);
  swap2Div("divStatus_"+lowerID,  "divStatus_"+upperID);
  swap2Div("divEditDel_"+lowerID, "divEditDel_"+upperID); 
}

//Find the last form which has name defined by parameter: formName.
function getLastFormInstance(formName) {
  var formNumber = document.forms.length;
  var p = 0;
  for (p = formNumber - 1; p >= 0; p--) {
    if (document.forms[p].name == formName) return document.forms[p];
  }
  return;  
}

//move one row up
function moveUp(rowID) {
  if (rowID<=0) return;
  
  // exchange the taskId  order
  var tmp;
  //theForm = document.forms["micrositeNaviInfoView"][1] not work in NetScape.
  var theForm = getLastFormInstance("dummyForm");
  
  tmp = theForm.taskId[rowID-1].value;

  theForm.taskId[rowID-1].value=theForm.taskId[rowID].value;
  theForm.taskId[rowID].value = tmp;

  var lowerID = rowIDMap[rowID];
  var upperID = rowIDMap[rowID-1];
  
  swap2Row(lowerID, upperID);
  
  // swap row id
  rowIDMap[rowID-1] = lowerID;
  rowIDMap[rowID] = upperID;
}

// move one row down
function moveDown(rowID) {
  var lowerRowID = rowID+1; 
  if ( lowerRowID >= numRow) return;
  
  moveUp(lowerRowID);
}

// Setup URL parameters to reorder tasks within the checlist
// Return true if task order was changed; false if not changed
function reorderTasks(theForm, url) {
  var i, len = rowIDMap.length;
  var changed = false;
  
  for(i=0; i<len; i++) {
    if ( i != rowIDMap[i] ) {
      changed = true;
    } 
  }
   
  if (changed) {
    theForm.action = url;
    theForm.submit();
  }
  
  return changed;
}

// reset task order
function resetOrder() {
  var rowID, k, lowerID, found, len = rowIDMap.length, tmp;
  
  for(rowID=0; rowID<len; rowID++) {
    if ( rowID != rowIDMap[rowID] ) {
	  found=false;
	  for (k=rowID+1; k<len && !found; k++) {
	    found = rowID==rowIDMap[k];
	  }
	  k--;
	  
      lowerID = rowIDMap[rowID];
	  swap2Row(lowerID, rowID);
	  
	  rowIDMap[k] = rowIDMap[rowID];
	  rowIDMap[rowID] = rowID;
    } 
  }
}

// -->
</script>

<!-- Zone 5 starts here.  -->
<table class="zoneFive" width="100%" border="0" cellspacing="0" cellpadding="0" 
         summary="content area">
  <tr>
    <td valign="top">
    
    <div class="pageTitle">
      <%@ include file="/cs/microsite/micrositeNaviInfo.jsp" %>
    </div> 
    
    <!--end page title area here-->

    <!--start title bar here-->
    <div class="pageSubtitle">
      <span class="left">
       <bean:write name="checklistTaskListView" property="checklistName"/>&nbsp;<bean:message key="cs.checklist"/>
      </span>
     <logic:notEqual name="checklistTaskListView" property="isReadOnly" value="true">
     <logic:equal name="checklistTaskListView" property="isOwner" value="true"> 
        <span class="right">
          <html:form action="/cs/checklistTaskNew.do">
            <bvhtml:hiddenList name="micrositeNaviInfoView" property="urlParams" scope="request"/>
            <%-- <input type=hidden name='maxTaskIndex' value='<bean:write name="checklistTaskListView" property="urlParams.maxTaskIndex" />' > --%>
            
            <input type="submit" class="titleButton" name="newBtn"
                 value='<bean:message key="button.createNew"/>'>
          </html:form>
        </span>
     </logic:equal>
     </logic:notEqual>
    </div> 
    
    <div class="blockWrap">
    <!-- start Page Instructions -->
    <logic:equal name="checklistTaskListView" property="isOwner" value="true">
      <div class="pageInstructions">
        <bean:message key="cs.checklist.instruction"/>
      </div>
    </logic:equal> 
    
   <html:form action="/cs/checklistList.do">
   <bvhtml:hiddenList name="micrositeNaviInfoView" property="urlParams" scope="request"/>

    <!-- Start List here -->
    <table class="dataTable" border="0" cellspacing="1" cellpadding="2" 
           summary="checklist task table" width="100%">
      <tr class="listHeader"> 
        <th id="Task" align="left"><bean:message key="cs.task"/></th>
        <th id="Owner" align="left"><bean:message key="cs.owner"/></th>
        <th id="Duedate" align="left"><bean:message key="cs.tasks.dueDate"/></th>
        <th id="Status" align="left"><bean:message key="cs.status"/></th>
        <logic:notEqual name="checklistTaskListView" property="isReadOnly" value="true">
          <logic:equal name="checklistTaskListView" property="isOwner" value="true">
            <th id="Reorder" align="left"><bean:message key="cs.checklist.reorder"/></th>
          </logic:equal>
        </logic:notEqual>
        <th id="Actions" align="left"><bean:message key="cs.actions"/></th>
      </tr>
   
  <% long rowID=0; %>
  <script language="JavaScript"> 
    var rowID2TaskID = new Array();
    var rowIDMap = new Array();   
  </script>
  
   <logic:iterate id="task" name="checklistTaskListView" 
             property="checklistTaskDTOList" indexId="index"> 	 
 <input type="hidden" name="taskId" value='<bean:write name="task" property="id"/>'/>
    <script language="JavaScript"> 
      rowIDMap[ <%= rowID %> ] =  <%= rowID %> ;
      rowID2TaskID[ <%= rowID %> ] = <bean:write name="task" property="id"/>;
    </script>
  <tr class='<%= (rowID&1)==1 ? "listEven" : "listOdd" %>'> 
    <td valign="top" > 
     <div id='divTask_<%= rowID %>' style="position:relative; width:100%;left:0; top:0; display:block; visibility: visible;" > 
        <b><html:link href="checklistTaskView.do" name="task" property="urlParams"><bean:write name="task" property="name"/></html:link></b>
     </div>
    </td>
    <td valign="top"> 
     <div id='divOwner_<%= rowID %>' style="position:relative; width:100%;left:0; top:0; display:block; visibility: visible; " > 
        <bean:write name="task" property="ownerName"/> </div>
    </td>
    <td valign="top"> 
     <div id='divDueDate_<%= rowID %>' style="position:relative; width:100%;left:0; top:0; display:block; visibility: visible;" > 
        <bean:write name="task" property="dueDate" formatKey="format.datetime.tasklist"/> </div>
    </td>
    <td valign="top"> 
      <div id='divStatus_<%= rowID %>' style="position:relative; width:100%;left:0; top:0; display:block; visibility: visible; " > 
      <logic:equal name="task" property="taskStatus" value="0">
       <bean:message key="cs.status.assigned"/> 
      </logic:equal>
      <logic:equal name="task" property="taskStatus" value="1">
      <bean:message key="cs.status.pending"/> 
      </logic:equal>
      <logic:equal name="task" property="taskStatus" value="2">
      <bean:message key="cs.status.completed"/> 
      </logic:equal>
      <logic:equal name="task" property="taskStatus" value="3">
      <bean:message key="cs.status.active"/> 
      </logic:equal>
      <logic:equal name="task" property="taskStatus" value="4">
      <bean:message key="cs.status.deferred"/> 
      </logic:equal>
      </div>
    </td>
    <logic:notEqual name="checklistTaskListView" property="isReadOnly" value="true">
    <logic:equal name="checklistTaskListView" property="isOwner" value="true">
    <td valign="top" width="60px"><a href="JavaScript: moveUp(<%= rowID %>)">
      <html:img page="/cs/images/action/icon_up.gif" styleClass="actionIcon" border="0" altKey="cs.action.moveUp" /></a>
      <a href="JavaScript: moveDown(<%= rowID %>)">
      <html:img page="/cs/images/action/icon_down.gif" styleClass="actionIcon" border="0" altKey="cs.action.moveDown" /></a></td>
    </logic:equal>
    </logic:notEqual>
    <td valign="top" ><div id='divEditDel_<%= rowID %>' style="position:relative; width:120px;left:0; top:0; display:block; visibility: visible; border:0; padding:0; margin:0; vertical-align:top">
      <logic:notEqual name="task" property="isReadOnly" value="true">
      <logic:equal name="task" property="owner" value="true">
      <html:link page="/cs/checklistTaskEdit.do" name="task" property="urlParams" >
      <html:img page="/cs/images/action/icon_edit.gif" styleClass="actionIcon" border="0" altKey="cs.image.alt.edit" />
      </html:link> <html:link page="/cs/checklistTaskDelete.do" name="task" property="urlParams" onclick="return confirmDelete()"><html:img page="/cs/images/action/icon_delete.gif" styleClass="actionIcon" border="0" altKey="cs.image.alt.delete" /></html:link>
      
      </logic:equal>
      </logic:notEqual>      
      </div>
    </td>
  </tr>

    <% rowID++; %>
  </logic:iterate> 
      <logic:equal name="checklistTaskListView" property="checklistTaskDTOList.empty" value="true">
        <tr class="listOdd">
          <td align="center" colspan="6">
            <bean:message key="cs.collaboration.noTasks"/>
          </td>
        </tr>
      </logic:equal>
  
</table>

<script language="JavaScript"> var numRow = <%= rowID %>; </script>

<!--start cancel, reset, save bar area here-->
<logic:notEqual name="checklistTaskListView" property="isReadOnly" value="true">
<logic:equal name="checklistTaskListView" property="isOwner" value="true">
<!--start cancel, reset, save bar area here-->

  <div class="pageButtonWrap" align="right">
    <input type="button" class="pageButton" name="resetBtn" 
                onclick="return resetOrder()"
        value='<bean:message key="button.reset"/>'>  
	&nbsp;&nbsp;
    <input type="button" class="pageButton" name="cancelBtn" 
           onclick="onClickButton(this.form, '<html:rewrite page="/cs/checklistList.do"/>')"
           value='<bean:message key="button.cancel"/>'>
           
    <input type="button"  class="pageButton" name="saveNewOrderBtn"
           onclick="reorderTasks(this.form, '<html:rewrite page="/cs/checklistReorderTasks.do"/>')"
           value='<bean:message key="button.saveNewOrder"/>'>
            
  </div>     
</logic:equal>
</logic:notEqual>
<!--end cancel, reset, save bar area here-->
</html:form>

  </div>
</td>
  </tr>
</table>
<!--end zone 5 content here -->

